<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function(){
            var obj = {name:"猪八戒",age:18,gender:"man"};
            // js对象--->JSON
            // JSON.stringify()可以将一个js对象转换为JSON,并以字符串的方式返回
            var s1 = JSON.stringify(obj);
            console.log(typeof s1);
            // string
            console.log(s1);
            // {"name":"猪八戒","age":18,"gender":"man"}

            // JSON--->js对象
            // JSON.parse()可以将JSON转换为js对象并返回
            var obj1 = JSON.parse(s1);
            console.log(typeof obj1);
            // object
            console.log(obj1.name);
            // 猪八戒
        }
    </script>
</head>
<body>
    
</body>
</html>